package com.sysu.ooad.action;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.sysu.ooad.entity.Student;
import com.sysu.ooad.service.StudentService;

@Component
@Scope("prototype")
public class StudentAction extends CommonAction {
	
	private static final long serialVersionUID = 1L;
	
	private StudentService studentService;

	private String name;
	private String password;
	
	
	public StudentService getStudentService() {
		return studentService;
	}

	@Resource
	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public String execute() throws Exception {
		return Action.SUCCESS;
	}
	
	public String login() throws Exception{
		Student student = studentService.login(name, password);
		if(student != null) {
			session.put("student", student);
			return Action.SUCCESS;
		}
		return Action.ERROR;
	}
}
